package com.tag;


import com.common.TokenUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;

public class TokenTag extends TagSupport {

    @Override
    public int doStartTag() throws JspException {
        try {
            JspWriter writer = pageContext.getOut();
            StringBuffer outRet = new StringBuffer("<input type='hidden' name='");
            outRet.append(TokenUtil.TOKEN_NAME).append("' value='").append(TokenUtil.setSessionToken((HttpServletRequest) pageContext.getRequest())).append("'/>");
            writer.write(outRet.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return super.doStartTag();
    }
}